// JavaScript Document
(function ($) {
    $.fn.myScroll = function (options) {
        //默认配置
        var defaults = {
            speed: 40,  //滚动速度,值越大速度越慢
            // rowHeight: 24 //每行的高度
        };

        var opts = $.extend({}, defaults, options);
        var box = $(this);
        var body = box.find('.scroll-body');
        var requestID = '';
        var y = 0;
        var _t = 0;

        var obj = {
            ready: function (t) {
                if(t-_t>opts.speed){

                    body.css({
                        transform: 'translateY('+y+'px)'
                    });

                    if(body.height()-box.height()+y<=0){
                        y = 0;
                    }
                    y --;
                    _t = t;
                }
                requestID = requestAnimationFrame(obj.ready);
            }
        };

        requestID = requestAnimationFrame(obj.ready);

        box.on('mouseenter', function () {
            //停止
            cancelAnimationFrame(requestID);
        }).on('mouseleave', function () {
            //开始
            requestID = requestAnimationFrame(obj.ready);
        });

    }

})(jQuery);